﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EMall.ProductService.Products
{
    public class ProductEntityTypeConfiguration : IEntityTypeConfiguration<Product>
    {
        public void Configure(EntityTypeBuilder<Product> builder)
        {
            builder.ToTable("Products");
            builder.HasKey(p => p.Id);
            builder.Property(p => p.Name).IsRequired();
            builder.Property(p => p.Model).IsRequired();
            builder.Property(p => p.Description).IsRequired();
            builder.Property(p => p.CategoryId).IsRequired();
            builder.Property(p => p.BrandId).IsRequired();
            builder.Property(p => p.IsActive).IsRequired().HasDefaultValue(false);
            builder.Property(p => p.CreatedTime).IsRequired();
        }
    }
    public class PictureEntityTypeConfiguration : IEntityTypeConfiguration<Picture>
    {
        public void Configure(EntityTypeBuilder<Picture> builder)
        {
            builder.ToTable("ProductPictures");
            builder.HasKey(p => p.Id);
            builder.Property<int>("ProductId").IsRequired();
            builder.Property(q => q.Url).IsRequired();
        }
    }
}